package com.dong.aop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * description
 *
 * @author Administrator 2021/09/09 18:44
 */
@Component
@Aspect
public class MyServiceAspect {

    @DeclareParents(value = "com.dong.aop.aspect.*+", defaultImpl = MyIntroductionImpl.class)
    private MyIntroduction myIntroduction;

    @Before("com.dong.aop.aspect.MyAspect.test()&&"+"this(myIntroduction)")
    public void before(JoinPoint joinPoint,MyIntroduction myIntroduction){
        System.out.println("before");
        myIntroduction.introduction();
    }

    @After("com.dong.aop.aspect.MyAspect.test()")
    public void after(){
        System.out.println("after");
    }

    @AfterReturning("com.dong.aop.aspect.MyAspect.test()")
    public void afterReturning(){
        System.out.println("afterReturning");
    }

    @AfterThrowing("com.dong.aop.aspect.MyAspect.test()")
    public void afterThrowing(){
        System.out.println("afterThrowing");
    }

    @Around("com.dong.aop.aspect.MyAspect.test() &&"+" args(name)")
    public void around(ProceedingJoinPoint point,String name) throws Throwable {
        System.out.println("before around "+ name);
        Object[] objects = new Object[1];
        objects[0] = name;
        point.proceed(objects);
        System.out.println("after around " + name);
    }
}
